<?php

function db_connect(){
	global $_GC;
	$link = mysql_connect($_GC['database']['host'], $_GC['database']['user'], $_GC['database']['password']) or die("no connection");
	$_GC['database']['link'] = $link;
	return $link;
}

function db_select_db(){
	global $_GC;
	$result = mysql_select_db($_GC['database']['dbname'], $_GC['database']['link']);
	return $result;
}

function db_open(){
	db_connect();
	db_select_db();
}

function db_close(){
	global $_GC;
	mysql_close($_GC['database']['link']);
}

function db_query($query){
	global $_GC;
	$hasil = mysql_query($query, $_GC['database']['link']);
	// echo(mysql_error($_GC['database']['link']) . "<br>");
	return $hasil;
}

function db_error(){
	global $_GC;
	$err = mysql_error($_GC['database']['link']);
	return db_errno() . ' : ' . trim($err);
}

function db_errno(){
	global $_GC;
	$err = mysql_errno($_GC['database']['link']);
	return trim($err);
}

function db_fetch_array($hasil){
	if(empty($hasil)){
		return null;
	}
	
	global $_GC;
	$baris = mysql_fetch_array($hasil);
	return $baris;
}

function db_fetch_row($hasil){
	global $_GC;
	$baris = mysql_fetch_row($hasil);
	return $baris;
}

function db_num_rows($hasil){
	global $_GC;
	$num = mysql_num_rows($hasil);
	return $num;
}
?>